# import numpy as np
#
# y_vals=np.array([1 if y==0 else -1 for y in range(10)])
# print(y_vals)

# y = [1 if i==0 else -1 for i in range(10)]
# print(y)
# from django.contrib.auth.models import User
# user = User.objects.create_user('john', '', 'john1234')
#
# # 在这里，User对象已经可以保存到数据库中了。
# # 你还可以改变它的其它属性。
# user.is_staff = True
# user.save()
# import requests
# import json
# url = "https://www.dianxiaomi.com/package/getStateCount.json"
#
# headers = {
#     "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
#     "Cookie": "_ati=1800950527900; dxm_i=MjAxMjg5IWFUMHlNREV5T0RrIWRkMDYzYWZmOTMyNDhhZmZhMjA0N2FiNTJlY2FjZjg1; dxm_t=MTU1NDg4MzYxNSFkRDB4TlRVME9EZ3pOakUxIWZjNzliYTNlZWZhODAwMzcyYzVjNDU3MmY4MWEyZTE1; dxm_c=dEpGZTBubWkhWXoxMFNrWmxNRzV0YVEhOTU1MzljYjI0NTBmYjA0YWNmNTcwZmMyMTdkNmQ1MjQ; dxm_w=NTYxNmM0NjQ1OTBjOGFiOTVkNjk2YTQzMWZmNjA1ZWIhZHowMU5qRTJZelEyTkRVNU1HTTRZV0k1TldRMk9UWmhORE14Wm1ZMk1EVmxZZyE3NzljOTBlNzUwZTlmM2FjNjMzODViM2YwNjczZmZhNQ; dxm_s=y-_gYWPa5TFriBQ5TbPQNv1A3rLJzzFA3K26i57uccE; _dxm_ad_client_id=41CFEB6BFCFE954A87F1B34F17B64DB64; Hm_lvt_f8001a3f3d9bf5923f780580eb550c0b=1555131734,1555133542,1555205488,1555899179; Hm_lpvt_f8001a3f3d9bf5923f780580eb550c0b=1555899334; JSESSIONID=8D727E777E6F76B97AF3D48F3B4E8562; rememberMe=HAdNo7GyxNvfaZ9Y3b7BxKNEjWi1eZN5U0D11yqch0Pp4sGfyGYHJPYdFHYaJmHotq9J1plv+9ABcz67HKLbqzqoxXqOcmHM36gsEbYhQkmpU5Tlo43s1ECR9vLcZQ1evOMnH3FlENvuB/UfZya6GkaFOn4RTrqISoCwesN/D2ZzvcnVwFdp5KZipLrP2h85ifo0CE5MoA+TTo+cQ2HtF/OhqbwJItf5ZFmmEqQ/WJV/UMDnl/reoU4d3QhOPFsiAAXifb2ulQjLZP9jOpop2VS0NKu4dNsePXFRXGRqwiEdu+shKdE/h9UJSE5t2i2KZycYLWMqGJlLLFJQLaiCo51jey9PSevdbP1NLlka/zCmv2cXxxt08EbiKWZjT3N9IaHbH75EozQAs7CvpAx6JpJEYzrrBAjJbIdspzTO/BGIzI0D07cBJsgXwEDIt/A6hbwQlq2YczKQJce1v5nFny22hgZO32VG//bBne8b83ofZKyKO9qeB0uRiYOhunQFrYXqZ1spyATPK26VpHklx+VILOqRPQQsPOwuUc5uxGs="}
#
# response = requests.get(url=url, headers=headers)
# print(response.content.decode())
# json_dict = response.content.decode()
#
# str_dict = json.loads(json_dict)
#
# print(str_dict["orderCount"])
# dict = {"orderCount":{"countNum":0,"orderState":null,"printType":null,"storageId":0,"authId":0,"orderCount":0,"riskControlCount":0,"paidCount":5,"approvedCount":34,"processedCount":0,"processedOverseaCount":0,"allocatedHasCount":8,"allocatedOutCount":9,"allocatedExceptionCount":0,"shippedCount":0,"refoundCount":0,"ignoreCount":0,"voidedCount":38,"unNeedTrackNum":0,"unCommitNum":0,"applyingNum":0,"applyFailNum":0,"applySuccessNum":0,"committingNum":0,"commitFailNum":0,"commitSuccessNum":991,"unPrintJhNum":0,"printedJhNum":0,"unPrintMdNum":0,"printedMdNum":0,"changeTrackingNum":0,"changeMdNum":0,"changeFinishNum":0,"authMap":null}}

# dict = {"a":1}
# print(dict['a'])
# from vne_erp.vne_erp.libs.captcha.captcha import captcha
#
# text, image = captcha.generate_captcha()
# print(text)


# import string
#
# s = 'quick'
#
# print(s)
# print(string.capwords(s))


# FASTDFS
# from fdfs_client.client import Fdfs_client
#
#
# client = Fdfs_client(r'D:\workspace\workSpacePycharm\VNE_ERP1\vne_erp\vne_erp\utils\fastdfs\client.conf')
#
#
# a = client.upload_appender_by_buffer(r'D:\workspace\workSpacePycharm\VNE_ERP1\front_end_pc\image\po.jpg'.encode('utf-8'))
#
# print(a)
import datetime
import json
from pprint import pprint

import pymysql
import xmltodict
from mws import mws

from vne_erp.vne_erp.utils.iosformat import isoformat


marketplaceids = ['A1AM78C64UM0Y8', 'A2EUQ1WTGCTBG2', 'ATVPDKIKX0DER']

# ******************************************************************************************************
access_key = 'AKIAITNXOMXBNOGOAHMQ'
secret_key = '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'
SellerId = "AXJGQAHIXO0GH"
MWSToken = "amzn.mws.1eb6a110-d7ba-3bea-481e-ff3006711b67"

order_update_time = datetime.datetime(2019, 7, 1)

CreatedAfter = isoformat(order_update_time)
#
x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=str(SellerId), auth_token=str(MWSToken))
try:
    # orders = x.list_orders(created_after=CreatedAfter, marketplaceids=marketplaceids)
    orders = x.get_report(report_id='16735598598018161')
except Exception as e:
    print(str(e))
# print(orders)
# print(orders,type(orders))
# file = open(orders,'rb')
# a = file.read()
# print(a)
# file.close()
response_data = orders.original
# datas = xmltodict.parse(response_data)
# data = mws.DictWrapper(response_data,None)
# data = data.parsed
# print(data)
# print(datas)\
path = response_data.decode()
with open('./report',mode="w") as f:
    f.write(path)

with open('./report',mode="r") as f:
    while True:
        x = f.readline()
        if x:
            alist = x.split('\t')
            for i in range(len(alist)-1,-1,-1):
                if alist[i] == '':
                    alist.remove('')
            print(alist)
        else:
            break


# xml_dict = xmltodict.parse(response_data)
# print(xml_dict)
# ******************************************************************************************************

# access_key1 = 'AKIAITNXOMXBNOGOAHMQ'  # replace with your access key
# secret_key1 = 'X/Py9553cKqfcDmpP9DVguSE3/i/oVr5RFoHORBh'  # replace with your secret key
#
# SellerId1 = "A2VZ2VCW85W234"
# MWSToken1 = "amzn.mws.0ab5e85e-de2f-fd3d-d8b3-833d650f418c"
#
#
# x = mws.Orders(access_key=access_key, secret_key=secret_key, account_id=SellerId, auth_token=MWSToken)
#
# CreatedAfter = isoformat(datetime.datetime(2019, 8, 1))
#
# try:
#     orders = x.list_orders(created_after=CreatedAfter, marketplaceids=marketplaceids)
# except Exception as e:
#     print(str(e))
#
# response_data = orders.original
# dict = mws.DictWrapper(response_data)
# print(dict.parsed['ListOrdersResult']['Orders']['Order'])
# xml_dict = xmltodict.parse(response_data)
# pprint(xml_dict)

"""全局变量应用测试"""
# global val
# val = list()
#
# def test1():
#     global val
#     val = [
#         '店铺1更新3',
#         '店铺2更新4',
#         '店铺5更新6',
#            ]
#
# def test3():
#     global val
#     val = ['123']
#
#
# def test2():
#     global val
#     print(val)
#
# test1()
# test2()
# test3()
# test2()

"""更新数据库图片"""

# import json
# import time
#
# import requests
# import pymysql
#
#
#
# class ImageToMysql(object):
#
#     def __init__(self):
#         self.url = ''
#         self.headers = ''
#
#     def counter_data(self,response_data):
#         """
#         数据提取与转换
#         [{"ImageUrl":"www.123123.com/1.jpg","ASIN":"7RW3SAF12QW"},....]
#         """
#
#         pass
#
#     def get_response_data(self,ASIN_LIST):
#
#         # 2 爬取数据
#         pass
#
#     def data_to_mysql(self, cur, data_of_list):
#         "数据存入mysql"
#         for i in data_of_list:
#             sql = """UPDATE tb_order_items SET GoodsImage = {} WHERE ASIN = {}""".format(i['ImageUrl'], i['ASIN'])
#         cur.execute(sql)
#
#     def get_mysql_data(self, cur):
#         sql = """SELECT ASIN FROM tb_order_items WHERE GoodsImage = ''"""
#         cur.execute(sql)
#         sql_data = cur.fetchall()
#         ASIN_LIST = list()
#         for i in sql_data:
#             ASIN_LIST.append(i[0])
#         return ASIN_LIST
#
# # 5  34  0  0  9  8  0  991 0 38
#
# if __name__ == "__main__":
#
#
#
#         # 和数据库建立连接
#     conn = pymysql.connect('192.168.10.17', 'vne123', '123', charset='utf8')
#
#     # 创建游标
#     cur = conn.cursor()
#
#     # 选择数据库
#
#     cur.execute('use vnemy')
#
#
#
#     # 导入数据
#     # 1 创建对象
#
#     sfx = ImageToMysql()
#     # 获取AINS列表
#     ASIN_data = sfx.get_mysql_data(cur)
#     print(ASIN_data)
#
#
#     # 2 爬取数据
#     # response = sfx.get_response_data(ASIN_data)
#     #
#     # # 3 数据转换与提取
#     # data_list = sfx.counter_data(response)
#     #
#     # # 4 将数据存入mysql
#     # sfx.data_to_mysql(cur, data_list)
#
#     cur.close()
#     conn.commit()
#     # 关闭数据库服务器连接，释放内存
#     conn.close()

# def demo(aaa):
#
#     print(*aaa)
#
#
# gl_dict = {"name": "小明", "age": 18}
# demo(gl_dict)
# a = None
# a = dict()
# a['key'] = 1
# print(a)

    # 和数据库建立连接
# conn = pymysql.connect('47.52.228.7', 'root', 'mysql', charset='utf8')
#
# # 创建游标
# cur = conn.cursor()
#
# # 选择数据库
#
# cur.execute('use vnemy')
#
# data_of_list = [
#     {
#         "store": "xxx",
#         "store_ip": "",
#         "seller_id": "",
#         "mws_token": "",
#         'id': "1"
# },
#     {},
#     {}]   #店铺列表
#

#
# for i in data_of_list:
#     sql = """UPDATE tb_order_items SET GoodsImage = {} WHERE ASIN = {}""".format(i['ImageUrl'], i['ASIN'])
# cur.execute(sql)
#
# cur.close()
# conn.commit()
# # 关闭数据库服务器连接，释放内存
# conn.close()
# class Demo:
#     def __init__(self,a_demo):
#         self.a = a_demo
#
#     def test1(self):
#         self.a += 1
#         print(self.a)
#
# demo = Demo(1)
# demo.test1()
